import request from '../index'

/**
 * 用户注册
 * @param nickname {string}
 * @param password {string}
 * @returns {Promise}
 */
export function userRegister(nickname, password) {
  return request({
    url: '/users',
    method: 'POST',
    data: {
      nickname,
      password
    }
  })
}

/**
 * 用户登录
 * @param nickname {string}
 * @param password {string}
 * @returns {Promise}
 */
export function userLogin(nickname, password) {
  return request({
    url: '/auth/login',
    method: 'POST',
    data: {
      nickname,
      password
    }
  })
}

/**
 * 获取用户密保
 * @param nickname {string}
 * @returns {Promise}
 */
export function getUserSecret(nickname) {
  return request({
    url: '/secret',
    params: {
      nickname
    }
  })
}

/**
 * 验证用户密保答案
 * @param id {string | number}
 * @param answer {string}
 * @returns {Promise}
 */
export function verifySecret(secretId, answer, password, userId) {
  return request({
    url: `/secret/verify`,
    method: 'POST',
    data: {
      secretId,
      answer,
      password,
      userId
    }
  })
}

/**
 * 获取用户详情
 * @param userId {string | number}
 * @returns {Promise}
 */
export function getUserProfile(userId) {
  return request({
    url: '/profile',
    params: {
      userId
    }
  })
}

/**
 * 获取用户作品
 * @param id {string | number}
 * @returns {Promise}
 */
export function getUserOpus(userId) {
  return request({
    url: '/opus',
    params: {
      userId
    }
  })
}
